// navigation.js
Page({
  data: {
    longitude: 121.472644,
    latitude: 31.231706,
    markers: [],
    polyline: []
  },

  onLoad() {
    this.initMap()
  },

  async initMap() {
    // 获取当前位置
    const res = await wx.getLocation({ type: 'gcj02' })
    this.setData({
      longitude: res.longitude,
      latitude: res.latitude,
      markers: [{
        id: 0,
        latitude: res.latitude,
        longitude: res.longitude,
        iconPath: '/assets/start.png',
        width: 25,
        height: 30
      },{
        id: 1,
        latitude: 31.179696,  // 示例目的地坐标
        longitude: 121.433451,
        iconPath: '/assets/end.png',
        width: 25,
        height: 30
      }],
      polyline: [{
        points: [
          {latitude: res.latitude, longitude: res.longitude},
          {latitude: 31.179696, longitude: 121.433451}
        ],
        color: "#409EFF",
        width: 4
      }]
    })
  },

  startNavigation() {
    wx.openLocation({
      latitude: 31.179696,
      longitude: 121.433451,
      name: '目的地',
      address: '上海市徐汇区收货点'
    })
  },

  backToDetail() {
    wx.navigateBack()
  }
})